<?php
session_start();
require_once "include/database.php";
$db = db_connect();
require_once "include/auth.php";

$user = credentials_valid($_POST['username'], $_POST['password']);
if($user){
  log_in($user['Username']);
  
  if($_SESSION['redirect_to']){
    header("Location: " . $_SESSION['redirect_to']);
    unset($_SESSION['redirect_to']);

  }else{
    header("Location: index.php");
  }
}else{
  header("Location: signin.php?error=1");
  exit("You are being redirected");
}
?>
